package com.tian.service.impl;

import com.alibaba.fastjson.JSON;
import com.tian.dto.SysLog;
import com.tian.elasticsearch.entity.SysLogESEntity;
import com.tian.elasticsearch.service.SysLogESService;
import com.tian.service.SysLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author tianwc  公众号：java后端技术全栈、面试专栏
 * @version 1.0.0
 * 博客地址：<a href="http://woaijava.cc/">博客地址</a>
 * <p>
 * 日志输出到ES中
 */
@Slf4j
@Service
public class ElasticSearchSysLogServiceImpl implements SysLogService {

    @Resource
    private SysLogESService sysLogESService;
    @Override
    public void logRecord(SysLog sysLog) {
        SysLogESEntity logEntity = new SysLogESEntity();
        logEntity.setLogContent(JSON.toJSONString(sysLog));
        logEntity.setIp(sysLog.getIp());
        logEntity.setUrl(sysLog.getUrl());
        logEntity.setMethodName(sysLog.getMethodName());
        sysLogESService.save(logEntity);
    }
}
